let http = require('http');
let https = require('https');
let path = require('path');
let ROOT = process.cwd();
let fs = require('fs')
let { HTTP_PORT, HTTPS_PORT } = require('../lib/config')
module.exports = app => {
    let httpPort = process.argv[2] || HTTP_PORT
    let httpsPort = process.argv[3] || +process.argv[2] + 1  || HTTPS_PORT 
    http.createServer(app)
        .listen(httpPort, () => console.log('listen at server' + httpPort))

    let key = fs.readFileSync(path.join(ROOT, './server/ssl/private.pem'))
    let cert = fs.readFileSync(path.join(ROOT, './server/ssl/file.crt'))

    https.createServer({ key, cert }, app)
        .listen(httpsPort, () => console.log('listen at server' + httpsPort))

}